<?php
namespace app\home\controller;

use cmf\controller\HomeBaseController;
use app\common\model\MytaskModel;
use app\common\model\RemindModel;
use app\common\model\AnserModel;
use app\common\model\LessonNameModel;
use app\common\model\LessonModel;
use app\common\model\ClassprogressModel;

//课程信息
class MytaskController extends HomeBaseController
{
	
	public function index(){
		$param = $this->request->param();
		MytaskModel::where('id',$param['id'])->setInc('look_num');
		$url = cmf_url('index_1',$param);
		$this->assign('title','');
		$this->assign('url',$url);
		return $this->fetch(":index");
	}

	public function index_1(){
		$param = $this->request->param();
		$data = MytaskModel::get($param['id'],'user');
		$day = RemindModel::where('user_id',$data['uid'])->value('day');
		$url = cmf_url('index_2',$param);
		$last_url = cmf_url('index',$param);
		$this->assign('url',$url);
		$this->assign('last_url',$last_url);
		$this->assign('data',$data);
		$this->assign('day',$day);
		return $this->fetch(":index_1");
	}

	public function index_2(){
		$param = $this->request->param();

		$data = AnserModel::where('taskid',$param['id'])->where('pid',3)->field('content')->find();
      
		$content = explode(',', $data['content']);
		$contentss = '';
		for ($i=0; $i < count($content)-1; $i++) { 
			if(!empty($content[$i])){
				$contents = explode('|', $content[$i]);
				$contentss[$i] = $contents[1];
			}
			
		}
	
		$url = cmf_url('index_3',['id'=>$param['id']]);
		//dump($url); 
		$last_url = cmf_url('index_1',$param);
		$this->assign('url',$url);
		$this->assign('last_url',$last_url);
		$this->assign('contentss',$contentss);
		return $this->fetch(":index_2");
	}

	public function index_3(){

		$param = $this->request->param();
		$data = AnserModel::where('taskid',$param['id'])->where('pid',4)->field('content')->find();
		$content = explode(',', $data['content']);
		$content = explode('|', $content[0]);
		$url = cmf_url('index_4',$param);
		$last_url = cmf_url('index_2',$param);
		$this->assign('url',$url);
		$this->assign('last_url',$last_url);
		$this->assign('content',$content);
		return $this->fetch(":index_3");
		
	}

	public function index_4(){
		
		$param = $this->request->param();

		$data = MytaskModel::get($param['id']);
		$lesson_ids = RemindModel::where('user_id',$data['uid'])->value('lesson_ids');
		$lesson_array = explode(',',$lesson_ids);
		//dump($lesson_array);
		$data = [];
		//课程ID
		foreach ($lesson_array as $key => $value) {
			$res = LessonModel::relation('names')->where('lesson_id',$value)->field('name_id,name')->find();
			if(!empty($res) && $res['name'] != '请选择课程'){
				$data[$key]['name'] = $res['names']['name_img'];
				$data[$key]['img'] = $res['names']['thumb'];
			}
		}
		
		$url = cmf_url('index_6',['id'=>$param['id']]);
		$url_more = cmf_url('more',['id'=>$param['id']]);
		$last_url = cmf_url('index_3',$param);
		$this->assign('url',$url);
		$this->assign('last_url',$last_url);
		$this->assign('url_more',$url_more);
		$this->assign('data',$data);
		return $this->fetch(":index_4");
	}


	public function more(){
		$param = $this->request->param();
		$data = MytaskModel::get($param['id']);
		$lesson_ids = RemindModel::where('user_id',$data['uid'])->value('lesson_ids');
		$lesson_array = explode(',',$lesson_ids);
		//dump($lesson_array);
		$data = [];
		//课程ID
		foreach ($lesson_array as $key => $value) {
			$res = LessonModel::relation('names')->where('lesson_id',$value)->field('name_id,name')->find();
			if(!empty($res) && $res['name'] != '请选择课程'){
				$data[$key]['name'] = $res['names']['name_img'];
				$data[$key]['img'] = $res['names']['thumb'];
			}
		}
		$last_url = cmf_url('index_4',$param);
		$this->assign('data',$data);
		$this->assign('last_url',$last_url);
		return $this->fetch(":more");
	}


	public function index_6(){
		$param = $this->request->param();
		$data = MytaskModel::get($param['id'],'user');
		$this->assign('data',$data);
		$last_url = cmf_url('index_4',$param);
		$url = cmf_url('index_7',$param);
		$this->assign('url',$url);
		$this->assign('last_url',$last_url);
		return $this->fetch(":index_6");

	}
	public function index_7(){
		$param = $this->request->param();
		$last_url = cmf_url('index_6',$param);
		$urllink = 'http://'.$_SERVER['SERVER_NAME'].'/mytask?id='.$param['id'];
		$img = 'http://'.$_SERVER['SERVER_NAME'].'/themes/simpleboot3/public/home/img/bg1_th.jpg';
		$this->assign('last_url',$last_url);
		$this->assign('urllink',$urllink);
		$this->assign('img',$img);
		return $this->fetch(":end");

	}

	//课程介绍
	public function lession(){
		$data = LessonNameModel::all();
		$this->assign('data',$data);
		$this->assign('title','课程介绍');
		return $this->fetch(":lession");	
	}
}

